package com.zhiyou100.api.list_demo;

import java.util.LinkedList;

public class Demo2 {

    public static void main(String[] args) {
        test1();
    }


    public static void test1(){
        Student stu1 = new Student("jack", 20);
        Student stu2 = new Student("tom", 21);
        Student stu3 = new Student("rose", 19);
        Student stu4 = new Student("lucy", 25);
        //创建一个LinkedList集合对象
        LinkedList<Student> list = new LinkedList<>();
        list.add(stu2);
        list.add(stu3);
        list.add(null);
        list.add(null);
        //将指定元素添加到此集合的开头
        list.addFirst(stu1);
        //将指定元素添加到此集合的末尾
        list.addLast(stu4);
        System.out.println("list = " + list);
        //获取第一个元素
        Student first = list.getFirst();
        System.out.println("first = " + first);
        //获取最后一个元素
        Student last = list.getLast();
        System.out.println("last = " + last);
        //移除第一个元素   返回值是被移除的元素
        Student student = list.removeFirst();
        System.out.println("移除第一个后：" + list);
        //移除最后一个
        Student last1 = list.removeLast();
        System.out.println("移除末尾元素后：" + list);
    }


}
